﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Repository;
using PersonalHealth.Data.Model;
using Core.UnitOfWork;
using PersonalHealth.Data.Data;

namespace PersonalHealth.Data.Repository
{
    public class OfficalDataThresholdRepository : Repository<OfficalDataThreshold>, IOfficalDataThresholdRepository
    {
        public OfficalDataThresholdRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {

        }

        #region IOfficalDataThresholdRepository 成员

        public IDictionary<string, OfficalDataThreshold> GetThreshold(string measureType)
        {
            var context = UnitOfWork.Context as HealthContext;
            var q = (from t in context.MeasureTypes
                     join st in context.MeasureSubTypes on t.Id equals st.MeasureTypeId
                     join os in context.OfficalDataThresholds on st.Id equals os.MeasureSubTypeId
                     where t.Code == measureType
                     select os).Distinct();
            IDictionary<string, OfficalDataThreshold> dict = new Dictionary<string, OfficalDataThreshold>();
            foreach (var i in q)
            {
                dict.Add(i.MeasureSubType.Code, i);
            }
            return dict;
        }

        #endregion
    }
}
